import os

# 使用srec_cat.exe将二进制文件转换为十六进制
os.system('srec_cat.exe qboot_1st.bin -Binary -offset 0x00000000 -o qboot_1st.hex -Intel')
os.system('srec_cat.exe 0x8000bin.bin -Binary -offset 0x00008000 -o 0x8000bin.hex -Intel')
os.system('srec_cat.exe 0x9000bin.bin -Binary -offset 0x00009000 -o 0x9000bin.hex -Intel')
os.system('srec_cat.exe 0xA000bin.bin -Binary -offset 0x0000A000 -o 0xA000bin.hex -Intel')
os.system('srec_cat.exe 0xB000bin.bin -Binary -offset 0x0000B000 -o 0xB000bin.hex -Intel')
os.system('srec_cat.exe qboot_2nd.bin -Binary -offset 0x0000D000 -o qboot_2nd.hex -Intel')
os.system('srec_cat.exe APP_X_R1.bin -Binary -offset 0x00025000 -o APP_X_R1.hex -Intel')

# 使用srec_cat.exe合并十六进制文件
os.system('srec_cat.exe qboot_1st.hex -Intel -fill 0xff 0x00000000 0x00008000 '
            '0x8000bin.hex -Intel -fill 0xff 0x00008000 0x00009000 '
            '0x9000bin.hex -Intel -fill 0xff 0x00009000 0x0000A000 '
            '0xA000bin.hex -Intel -fill 0xff 0x0000A000 0x0000B000 '
            '0xB000bin.hex -Intel -fill 0xff 0x0000B000 0x0000D000 '
            'qboot_2nd.hex -Intel -fill 0xff 0x0000D000 0x00025000 '
            'APP_X_R1.hex -Intel -o MergedHexFile.hex -Intel')

# 删除除了MergedHexFile.hex之外的各个十六进制文件
for filename in os.listdir('.'):
    if filename.endswith('.hex') and filename != 'MergedHexFile.hex':
        os.remove(filename)

print('完成！')